package top.kaoshanji.p3ch04a;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;
import top.kaoshanji.p3ch04a.mapper.ProvinceMapper;
import top.kaoshanji.p3ch04a.model.Province;
import top.kaoshanji.p3ch04a.util.SqlSessionUtil;

/**
 * @author kaoshanji
 * ^_^
 * create time 2025/4/19 22:37
 */
public class ProvinceMapperTest {

    /**
     * 代码清单test-p3ch04a-101页a：根据省份id查询省份和城市集合（collection标签之关联嵌套映射）
     */
    @Test
    public void testFindProvinceById1() {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionUtil.getSqlSession();
            ProvinceMapper provinceMapper = sqlSession.getMapper(ProvinceMapper.class);

            Province province = provinceMapper.findProvinceById1(1);
            System.out.println(province);

        } finally {
            SqlSessionUtil.closeSqlSession(sqlSession);
        }
    }


    /**
     * 代码清单test-p3ch04a-103页a：根据省份id查询省份和城市集合（collection标签之关联嵌套查询）
     */
    @Test
    public void testFindProvinceById2() {
        SqlSession sqlSession = null;
        try {
            sqlSession = SqlSessionUtil.getSqlSession();
            ProvinceMapper provinceMapper = sqlSession.getMapper(ProvinceMapper.class);

            Province province = provinceMapper.findProvinceById2(1);
            System.out.println(province);

        } finally {
            SqlSessionUtil.closeSqlSession(sqlSession);
        }
    }



}
